local addon = LibStub("AceAddon-3.0"):GetAddon("Poppins")
local Group = addon.Group

local L = LibStub("AceLocale-3.0"):GetLocale("Poppins")

local fontValues = AceGUIWidgetLSMlists.font
local pointValues = { top = L["Up"], bottom = L["Down"], right = L["Right"], left = L["Left"], center = L["Around"], }
local buttonValues = { [false] = L["Nothing"], L["Cast and Set"], L["Cast"], L["Set"], }
local strataValues = { BACKGROUND = L["Background"], LOW = L["Low"], MEDIUM = L["Medium"], HIGH = L["High"] }
local justifyValues = { LEFT = L["Left"], CENTER = L["Center"], RIGHT = L["Right"], }

local function get(info)
	return addon:GetGroup(info[#info-2]):GetOption(info.arg or info[#info])
end
local function set(info, ...)
	addon:GetGroup(info[#info-2]):SetOption(info.arg or info[#info], ...)
end

Group.options = {
	general = {
		name = L["General"],
		desc = L["General options"],
		type = "group",
		order = 1,
		hidden = false,
		args = {
			copy = {
				name = L["Copy Options"],
				desc = L["Copy options from another button or group or the default"],
				type = "select",
				set = function(info, value)
					local name = info[#info-2]
					if value then
						addon:CopyOptions(value, name)
						addon:GetGroup(name):UpdateOptions()
					else
						addon:GetGroup(name):ResetOptions()
					end
				end,
				values = function(info)
					local t = { [false] = L["Default"] }
					for i in ipairs(addon.buttons) do
						t[i] = format(L["Button: %d"], i)
					end
					for group in pairs(addon.groups) do
						t[group] = format(L["Group: %s"], group)
					end
					t[info[#info-2]] = nil
					return t
				end,
				order = 1,
			},
		},
	},
	display = {
		name = L["Display"],
		desc = L["Visual options for the button and its popup buttons"],
		type = "group",
		order = 2,
		get = get,
		set = set,
		hidden = false,
		args = {
			header1 = {
				name = L["Button Options"],
				desc = L["Options for this button"],
				type = "header",
				order = 1,
			},
			alpha = {
				name = L["Alpha"],
				desc = L["Sets the buttons alpha"],
				type = "range",
				min = 0,
				max = 1,
				bigStep = 0.1,
				isPercent = true,
				disabled = false,
				order = 2,
			},
			scale = {
				name = L["Scale"],
				desc = L["Sets the buttons scale"],
				type = "range",
				min = 0.1,
				max = 2,
				bigStep = 0.1,
				isPercent = true,
				order = 3,
			},
			strata = {
				name = L["Frame Strata"],
				desc = L["Sets the buttons frame strata"],
				type = "select",
				values = strataValues,
				disabled = false,
				order = 4,
			},
			header4 = {
				type = "header",
				name = L["Popup Button Options"],
				desc = L["Options for the popup buttons"],
				order = 5,
			},
			popupalpha = {
				name = L["Alpha"],
				desc = L["Sets the popup buttons alpha"],
				type = "range",
				min = 0,
				max = 1,
				bigStep = 0.1,
				isPercent = true,
				disabled = false,
				order = 6,
			},
			popupscale = {
				name = L["Scale"],
				desc = L["Sets the popup buttons scale"],
				type = "range",
				min = 0.1,
				max = 2,
				bigStep = 0.1,
				isPercent = true,
				order = 7,
			},
			popupstrata = {
				name = L["Frame Strata"],
				desc = L["Sets the popup buttons frame strata"],
				type = "select",
				values = strataValues,
				disabled = false,
				order = 8,
			},
			padding = {
				name = L["Padding"],
				desc = L["Sets the popup buttons padding"],
				type = "range",
				min = -100,
				max = 100,
				bigStep = 1,
				order = 9,
			},
			direction = {
				name = L["Direction"],
				desc = L["Sets the direction the popup buttons should point to"],
				type = "select",
				values = pointValues,
				order = 10,
			},
			offset = {
				name = L["Offset"],
				desc = L["Sets the popup buttons offset when the direction is set to 'Around'"],
				type = "range",
				min = 0,
				max = 359,
				bigStep = 1,
				disabled = function(info)
					return addon:GetGroup(info[#info-2]):GetOption("direction") ~= "center"
				end,
				order = 11,
			},
		},
	},
	text = {
		name = L["Text"],
		desc = L["Text Options"],
		type = "group",
		order = 5,
		get = get,
		set = set,
		hidden = false,
		args = {
			hotkey = {
				name = L["Hotkey"],
				desc = L["Hotkey"],
				type = "header",
				disabled = false,
				order = 1,
			},
			hotkeyShow = {
				name = L["Show Hotkeys"],
				desc = L["Shows or hides the hotkey"],
				type = "toggle",
				arg = { "hotkey", "show", },
				disabled = false,
				order = 2,
			},
			hotkeyFont = {
				name = L["Font"],
				desc = L["Sets the font"],
				type = "select",
				dialogControl = 'LSM30_Font',
				values = fontValues,
				arg = { "hotkey", "font", },
				disabled = false,
				order = 3,
			},
			hotkeySize = {
				name = L["Font Size"],
				desc = L["Sets the font size"],
				type = "range",
				min = 8,
				max = 15,
				step = 1,
				arg = { "hotkey", "size", },
				disabled = false,
				order = 4,
			},
			hotkeyJustify = {
				name = L["Justify"],
				desc = L["Sets the horizontal justifaction"],
				type = "select",
				values = justifyValues,
				arg = { "hotkey", "justify", },
				disabled = false,
				order = 5,
			},
			hotkeyX = {
				name = L["Offset: Horizontal"],
				desc = L["Sets the horizontal offset"],
				type = "range",
				min = -18,
				max = 18,
				step = 1,
				arg = { "hotkey", "x", },
				disabled = false,
				order = 6,
			},
			hotkeyY = {
				name = L["Offset: Vertical"],
				desc = L["Sets the vertical offset"],
				type = "range",
				min = -18,
				max = 18,
				step = 1,
				arg = { "hotkey", "y", },
				disabled = false,
				order = 7,
			},
			count = {
				name = L["Count & Macro"],
				desc = L["Count & Macro"],
				type = "header",
				disabled = false,
				order = 8,
			},
			countShow = {
				name = L["Show Counts"],
				desc = L["Shows or hides the item or spell count"],
				type = "toggle",
				arg = { "count", "show", },
				disabled = false,
				order = 9,
			},
			countFont = {
				name = L["Font"],
				desc = L["Sets the font"],
				type = "select",
				dialogControl = 'LSM30_Font',
				values = fontValues,
				arg = { "count", "font", },
				disabled = false,
				order = 10,
			},
			countSize = {
				name = L["Font Size"],
				desc = L["Sets the font size"],
				type = "range",
				min = 8,
				max = 15,
				step = 1,
				arg = { "count", "size", },
				disabled = false,
				order = 11,
			},
			countJustify = {
				name = L["Justify"],
				desc = L["Sets the horizontal justifaction"],
				type = "select",
				values = justifyValues,
				arg = { "count", "justify", },
				disabled = false,
				order = 12,
			},
			countX = {
				name = L["Offset: Horizontal"],
				desc = L["Sets the horizontal offset"],
				type = "range",
				min = -18,
				max = 18,
				step = 1,
				arg = { "count", "x", },
				disabled = false,
				order = 13,
			},
			countY = {
				name = L["Offset: Vertical"],
				desc = L["Sets the vertical offset"],
				type = "range",
				min = -18,
				max = 18,
				step = 1,
				arg = { "count", "y", },
				disabled = false,
				order = 14,
			},
			selected = {
				name = L["Selected"],
				desc = L["Selected Options"],
				type = "header",
				disabled = false,
				order = 15,
			},
			selectedShow = {
				name = L["Show Selected"],
				desc = L["Shows or hides the selected popup button's id"],
				type = "toggle",
				arg = { "selected", "show", },
				disabled = false,
				order = 16,
			},
			selectedFont = {
				name = L["Font"],
				desc = L["Sets the font"],
				type = "select",
				dialogControl = 'LSM30_Font',
				values = fontValues,
				arg = { "selected", "font", },
				disabled = false,
				order = 17,
			},
			selectedSize = {
				name = L["Font Size"],
				desc = L["Sets the font size"],
				type = "range",
				min = 8,
				max = 15,
				step = 1,
				arg = { "selected", "size", },
				disabled = false,
				order = 18,
			},
			selectedJustify = {
				name = L["Justify"],
				desc = L["Sets the horizontal justifaction"],
				type = "select",
				values = justifyValues,
				arg = { "selected", "justify", },
				disabled = false,
				order = 19,
			},
			selectedX = {
				name = L["Offset: Horizontal"],
				desc = L["Sets the horizontal offset"],
				type = "range",
				min = -18,
				max = 18,
				step = 1,
				arg = { "selected", "x", },
				disabled = false,
				order = 20,
			},
			selectedY = {
				name = L["Offset: Vertical"],
				desc = L["Sets the vertical offset"],
				type = "range",
				min = -18,
				max = 18,
				step = 1,
				arg = { "selected", "y", },
				disabled = false,
				order = 21,
			},
		},
	},
	clicks = {
		name = L["Click Actions"],
		desc = L["Sets the click actions for the buttons"],
		type = "group",
		order = 16,
		get = get,
		set = set,
		hidden = false,
		args = {
			left = {
				name = L["Left Button Action"],
				desc = L["Left Button Action"],
				type = "select",
				values = buttonValues,
				arg = { "clicks", 1, },
				order = 1,
			},
			right = {
				name = L["Right Button Action"],
				desc = L["Right Button Action"],
				type = "select",
				values = buttonValues,
				arg = { "clicks", 2, },
				order = 2,
			},
			middle = {
				name = L["Middle Button Action"],
				desc = L["Middle Button Action"],
				type = "select",
				values = buttonValues,
				arg = { "clicks", 3, },
				order = 3,
			},
		},
	},
}